#include<bits/stdc++.h>
#define md 1000000007
using namespace std;
int n;
int lowbit(int x)
{
    return x&(-x);
}
struct num
{
    int v,p;
    bool operator <(const num&a)const
    {
        return v<a.v;
    }
}a[1000010];
int ans;
int c[1000010];
int t;
int main()
{
    scanf("%d",&t);
    while(t--){
        memset(c,0,sizeof(c));
        ans = 0;
        scanf("%d",&n);
        for(int i=1;i<=n;++i)
        {
            scanf("%d",&a[i].v);
            a[i].v+=i;
            a[i].p=i;
        }
        sort(a+1,a+n+1);
        for(int i=1;i<=n;++i)
        {
            int x=a[i].p;
            while(x<=n)
            {
                ++c[x];
                x+=lowbit(x);
            }
            int s=0;
            x=a[i].p;
            while(x)
            {
                s+=c[x];
                x-=lowbit(x);
            }
            ans+=i-s;
            ans%=md;
        } 
        printf("%d\n",ans);
    }
    return 0;
}